package com.jiangyifen.robot.core.sipphone;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jiangyifen.robot.core.sipphone.peers.Config;
import com.jiangyifen.robot.core.sipphone.peers.media.MediaMode;
import com.jiangyifen.robot.core.sipphone.peers.sip.syntaxencoding.SipURI;
import com.jiangyifen.robot.entity.RobotYunXiaoMiEntity;


public class SipPhoneConfig implements Config {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	private RobotYunXiaoMiEntity robotEntity;
	
	private String localIpString = "";

	private InetAddress publicIpAddress;
	
	public SipPhoneConfig(RobotYunXiaoMiEntity robotEntity, String localIpString){
		this.robotEntity = robotEntity;
		this.localIpString = localIpString;
	}

	@Override
	public InetAddress getLocalInetAddress() {
		InetAddress inetAddress = null;
		try {
			inetAddress = InetAddress.getByName(localIpString);
		} catch (UnknownHostException e) {
			logger.error(e.getMessage(),e);
		}
		return inetAddress;
	}

	@Override
	public InetAddress getPublicInetAddress() {
		return publicIpAddress;
	}

	@Override
	public String getUserPart() {
		return robotEntity.getSipUsername();
	}

	@Override
	public String getDomain() {
		return robotEntity.getSipDomain();
	}

	@Override
	public String getPassword() {
		return robotEntity.getSipPassword();
	}

	@Override
	public MediaMode getMediaMode() {
		return MediaMode.captureAndPlayback;
	}

	@Override
	public String getAuthorizationUsername() {
		return getUserPart();
	}

	@Override
	public void setPublicInetAddress(InetAddress inetAddress) {
		publicIpAddress = inetAddress;
	}

	@Override
	public SipURI getOutboundProxy() {
		return null;
	}

	@Override
	public int getSipPort() {
		return 0;
	}

	@Override
	public boolean isMediaDebug() {
		return false;
	}

	@Override
	public String getMediaFile() {
		return null;
	}

	@Override
	public int getRtpPort() {
		return 0;
	}

	@Override
	public void setLocalInetAddress(InetAddress inetAddress) {
	}

	@Override
	public void setUserPart(String userPart) {
	}

	@Override
	public void setDomain(String domain) {
	}

	@Override
	public void setPassword(String password) {
	}

	@Override
	public void setOutboundProxy(SipURI outboundProxy) {
	}

	@Override
	public void setSipPort(int sipPort) {
	}

	@Override
	public void setMediaMode(MediaMode mediaMode) {
	}

	@Override
	public void setMediaDebug(boolean mediaDebug) {
	}

	@Override
	public void setMediaFile(String mediaFile) {
	}

	@Override
	public void setRtpPort(int rtpPort) {
	}

	@Override
	public void save() {
	}

	@Override
	public void setAuthorizationUsername(String authorizationUsername) {
	}

	public RobotYunXiaoMiEntity getRobotEntity() {
		return robotEntity;
	}

	public void setRobotEntity(RobotYunXiaoMiEntity robotEntity) {
		this.robotEntity = robotEntity;
	}

}
